﻿using log4net;
using Quartz;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;

namespace DService
{
    public class TestJob : IJob
    {
        private readonly ILog _logger = LogManager.GetLogger(typeof(TestJob));
        public void Execute(IJobExecutionContext context)
        {
            _logger.InfoFormat("开始执行"+DateTime.Now);
            Process.Start(@"D:\Repos\DChrome\DChrome.Windows\DChrome.Windows\bin\x64\Debug\DChrome.Windows.exe");
            Thread.Sleep(TimeSpan.FromSeconds(10));
            killProcess();
        }
        void killProcess()
        {
            Process[] pro = Process.GetProcesses();//获取已开启的所有进程
            //遍历所有查找到的进程
            for (int i = 0; i < pro.Length; i++)
            {
                //判断此进程是否是要查找的进程
                if (pro[i].ProcessName.ToString() == "DChrome.Windows")
                {
                    pro[i].Kill();//结束进程
                }
            }
        }
    }
}
